﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FaithCMS
{
    public class SessionManager
    {
        //User session values
        private static string _userID = "UserID";
        private static string _userRole = "UserRole";
        private static bool _authenticated = false;
        private static Status _userStatus = Status.Unknown;

        //Session Properties
        public static string UserID
        {
            get
            {
                if (HttpContext.Current.Session[SessionManager._userID] == null)
                {
                    return string.Empty;
                }
                else
                {
                    return HttpContext.Current.Session[SessionManager._userID].ToString();
                }
            }
            set
            {
                HttpContext.Current.Session[SessionManager._userID] = value;
            }
        }

        public static string UserRole
        {
            get
            {
                if (HttpContext.Current.Session[SessionManager._userRole] == null)
                {
                    return string.Empty;
                }
                else
                {
                    return HttpContext.Current.Session[SessionManager._userRole].ToString();
                }
            }
            set
            {
                HttpContext.Current.Session[SessionManager._userRole] = value;
            }
        }

        public static bool Authenticated
        {
            get
            {
                if (HttpContext.Current.Session[SessionManager._authenticated.ToString()] == null)
                {
                    return false;
                }
                else
                {
                    return (bool) HttpContext.Current.Session[SessionManager._authenticated.ToString()];
                }
            }
            set
            {
                HttpContext.Current.Session[SessionManager._authenticated.ToString()] = value;
            }
        }

        public static Status UserStatus
        {
            get
            {
                return _userStatus;
            }
            set
            {
                _userStatus = value;
            }
        }

        //Status enumeration used to determine what state the user is in ("LoggedIn", or "LoggedOut")
        public enum Status: int
        {
            LoggedIn = 1,
            LoggedOut = 0,
            Unknown = -1
        }
    }
}